//
//  CustomButton.m
//  F50
//
//  Created by zack on 15/5/20.
//  Copyright (c) 2015年 ZACK. All rights reserved.
//

#import "CustomButton.h"

@implementation CustomButton
+(void)initWithArray:(NSArray*)arr addSuper:(UIView*)who withHeight:(int)high withTag:(int)tag addTarget:(id)target action:(SEL)select{
    for (int i = 0 ; i < arr.count; i++) {
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    //正常状态
        button.tag= tag +i;
    
        [button setTitle:arr[i] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        button.backgroundColor = [UIColor clearColor];
        button.layer.borderColor = RGB(168, 197, 203).CGColor;
        button.layer.borderWidth = 1;
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        if (i == 0) {
            button.backgroundColor = RGB(76, 187, 251);
            [button setTitle:@"全部" forState:UIControlStateNormal];

        }
        switch (i/3) {
            case 0:
                button.frame = CGRectMake(15 + 10*i + (WIDTH/3 - 50/3)*i, high, (WIDTH - 50)/3, 30);
        
                break;
           case 1:
                button.frame = CGRectMake(15 + 10*(i-3) + (WIDTH/3 - 50/3)*(i-3), high +45 , (WIDTH - 50)/3, 30);
                
                break;
                
            case 2:
                button.frame = CGRectMake(15 + 10*(i-6) + (WIDTH/3 - 50/3)*(i-6), high +90 , (WIDTH - 50)/3, 30);
                
                break;

            default:
                break;
        }
   
    
    [button addTarget:target action:select forControlEvents:UIControlEventTouchUpInside];
    [who addSubview:button];
    }
}
@end
